package top.fyxxxx.dbdesign.servlet;

import top.fyxxxx.dbdesign.dao.DBoperate;
import top.fyxxxx.dbdesign.data.PersonalData;
import top.fyxxxx.dbdesign.util.CourseManager;
import top.fyxxxx.dbdesign.util.Manager;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/DeleteServlet")
public class DeleteServlet extends HttpServlet {
    CourseManager manager= Manager.courseManager();
    DBoperate dBoperate=DBoperate.getInstance();
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String Cid=request.getParameter("cid");
        long cid=Long.parseLong(Cid);
        long uid=(Long)request.getSession().getAttribute("uid");
        PersonalData pd=dBoperate.getPersonalData(uid,cid);
        if((pd.getPower()&1)==0)manager.exitCourse(uid,cid);
        else manager.destroyCourse(uid,cid);
        response.sendRedirect("teacherMainPage.jsp");
    }
}
